<?php

/**
 * This file is part of Webman AI.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 */

namespace plugin\ai\app\handler;

use Webman\Openai\Image;

class CogView extends Gpt3
{
    /**
     * @var string 模型处理器名称
     */
    protected static $name = '智普作图';

    /**
     * @var string 模型类型
     */
    protected static $type = 'cogview';

    /**
     * @var bool 余额是否可见
     */
    protected static $balanceVisible = false;

    /**
     * @var string[] 支持的模型
     */
    public static $models = [
        'cogview-3-plus',
        'cogview-3'
    ];

    /**
     * @var string[] 自定义配置
     */
    public static $defaultSettings = [
        'api' => [
            'name' => 'API',
            'type' => 'text',
            'value' => 'https://open.bigmodel.cn/api/paas/v4/',
            'desc' => '默认填写 https://open.bigmodel.cn/api/paas/v4/',
        ],
        'apikey' => [
            'name' => 'ApiKey',
            'type' => 'text',
            'value' => '',
        ],
        'regFreeCount' => [
            'name' => '注册赠送',
            'type' => 'number',
            'value' => 0,
        ],
        'dayFreeCount' => [
            'name' => '每日赠送',
            'type' => 'number',
            'value' => 0,
        ],
    ];

    /**
     * @var string 处理器
     */
    protected $driverClass = driver\Dalle::class;

    /**
     * Image
     * @param array $data
     * @param array $options
     * @return void
     */
    public function generations(array $data, array $options)
    {
        $settings = $this->getRealSettings($data['model']);
        $this->driver = new $this->driverClass($settings);
        $this->driver->generations($data, $options);
    }

    /**
     * 对话
     * @param $data
     * @param $options
     * @return void
     */
    public function completions($data, $options)
    {
        $this->driver = new $this->driverClass($this->getSettings());
        $this->driver->completions($data, $options);
    }

}